/* * CadastroMedicoPanel.java
 *
 * Created on 24/10/2010, 20:07:01
 */
package clinicapoo.view.medic;

import clinicapoo.factory.Services;
import clinicapoo.model.Especialidade;
import clinicapoo.model.Medico;
import clinicapoo.view.dialog.Dialogs;
import clinicapoo.view.main.MainFrame;
import clinicapoo.view.utils.JComboRenderer;
import java.awt.Component;
import java.util.List;
import javax.swing.DefaultComboBoxModel;

import static clinicapoo.message.MessageResources.msg;

/**
 * @author Administrador
 */
public class CadastroMedicoPanel extends javax.swing.JInternalFrame
{
	private List<Especialidade> listaEspecialidades;

	/** Creates new form CadastroMedicoPanel */
	public CadastroMedicoPanel()
	{
		initComponents();
		carregarListaEspecialidades();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        txt_celular = new javax.swing.JTextField();
        txt_telefone = new javax.swing.JTextField();
        txt_endereco = new javax.swing.JTextField();
        txt_nome = new javax.swing.JTextField();
        txt_crm = new javax.swing.JTextField();
        txt_cpf = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        cmbEspecialidade = new javax.swing.JComboBox();

        setClosable(true);
        setIconifiable(true);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("resources/messages"); // NOI18N
        setTitle(bundle.getString("view.medic.cadastro.title")); // NOI18N

        jLabel1.setText(bundle.getString("view.medic.cadastro.cpf")); // NOI18N

        jLabel2.setText(bundle.getString("view.medic.cadastro.crm")); // NOI18N

        jLabel3.setText(bundle.getString("view.medic.cadastro.nome")); // NOI18N

        jLabel4.setText(bundle.getString("view.medic.cadastro.endereco")); // NOI18N

        jLabel5.setText(bundle.getString("view.medic.cadastro.telefoneResidencial")); // NOI18N

        jLabel6.setText(bundle.getString("view.medic.cadastro.celular")); // NOI18N

        jButton1.setText(bundle.getString("view.medic.cadastro.cadastrar")); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel7.setText(bundle.getString("view.medic.cadastro.especialidade")); // NOI18N

        cmbEspecialidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txt_celular, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(txt_telefone, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(txt_endereco, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(txt_nome, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(txt_crm, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(txt_cpf, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(cmbEspecialidade, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(28, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(cmbEspecialidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txt_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txt_crm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txt_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txt_telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txt_celular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void carregarListaEspecialidades()
	{
		try
		{
			listaEspecialidades = Services.especialidade.listar();
			cmbEspecialidade.setModel(new DefaultComboBoxModel(listaEspecialidades.toArray()));
			cmbEspecialidade.setRenderer(new JComboRenderer());
		}
		catch (Exception e)
		{
			Dialogs.showError(this, e);
		}
	}

	private void atualizarListaMedicos()
	{
		MainFrame master = MainFrame.getInstance();
		Component c = master.getJanelasAbertas().get(ListaMedicosPanel.class);
		if (c != null)
		{
			ListaMedicosPanel p = (ListaMedicosPanel) c;
			p.mostrarListaMedicos();
		}
	}

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
		try
		{
			Medico m = new Medico();
			m.setEspecialidade((Especialidade)cmbEspecialidade.getSelectedItem());
			m.setCpf(txt_cpf.getText());
			m.setCrm(txt_crm.getText());
			m.setNome(txt_nome.getText());
			m.setEndereco(txt_endereco.getText());
			m.setTelefone(txt_telefone.getText());
			m.setCelular(txt_celular.getText());

			Services.medico.cadastrar(m);
			atualizarListaMedicos();
			Dialogs.showInfo(this, msg("view.medic.cadastrar.sucesso"));
		}
		catch (Exception e)
		{
			Dialogs.showError(this, e);
		}
	}//GEN-LAST:event_jButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbEspecialidade;
    protected javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    protected javax.swing.JTextField txt_celular;
    protected javax.swing.JTextField txt_cpf;
    protected javax.swing.JTextField txt_crm;
    protected javax.swing.JTextField txt_endereco;
    protected javax.swing.JTextField txt_nome;
    protected javax.swing.JTextField txt_telefone;
    // End of variables declaration//GEN-END:variables
}
